//
// Created by vcq on 21/2/9.
//
#pragma once

#include "dbng.hpp"

struct syllabus {
    int id;
    string name;//课程名
    string note;
    int _grade_id; //年级
    int _course_id;
    int _plan_id;
};
REFLECTION(syllabus, id, name, _grade_id, _course_id, _plan_id, note)

json MGetSyllabusData(basic_string_view<char> id, basic_string_view<char> _plan_id, vector<string> ids) {
    string sql = "select * from `syllabus` where 1=1 ";
    if (!id.empty()) {
        sql += " and id = ";
        sql += id;
    }
    if (!_plan_id.empty()) {
        sql += " and _plan_id = ";
        sql += _plan_id;
    }
    if (!ids.empty()) {
        sql += " and id in ( -989";
        for (auto i : ids) {
            sql += ",";
            sql += i;
        }
        sql += ") ";
    }
    Dao dao;
    nlohmann::json article_list, ret, item;
    auto v = dao.query<syllabus>(sql);
    for (auto &o : v) {
        item["id"] = o.id;
        item["name"] = o.name;
        item["_grade_id"] = o._grade_id;
        item["_course_id"] = o._course_id;
        item["_plan_id"] = o._plan_id;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}
void MSaveSyllabus(const struct syllabus& syllabus1){
    Dao dao;
    dao.update_object(syllabus1);
}
void MDeleteSyllabus(basic_string_view<char> id){
    MDeleteAll("syllabus",id);
}